package com.tjsinfo.tjsoa.workplan.dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.tjsinfo.tjsoa.workplan.vo.WorkPlanDefine;
import com.tjsinfo.tjsoa.workplan.vo.WorkPlanExamine;
import com.tjsinfo.tjsoa.workplan.vo.WorkPlanMain;

public class WorkPlanExamineDao extends HibernateBaseDao implements IWorkPlanExamineDao{
	public List selectSuddenlyWorkPlan(final Integer userid,final Integer start)
	{

		return (List)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{

					public Object doInHibernate(Session arg0)
							throws HibernateException, SQLException {
						// TODO Auto-generated method stub
						Query query =	arg0.createQuery("from WorkPlanExamine work inner join fetch  work.workPlanMain inner join fetch  work.workPlanMain.tjsUser where work.tjsUser.id = ? and work.examineState = ?");
						query.setParameter(0, userid);
						query.setParameter(1, start);
						return query.list();
					}
					
				});
	}
	/**
	 * 根据计划ID和批示人id查询
	 */
	public WorkPlanExamine selectWorkPlan(final Integer userid,final String jihua)
	{

		return (WorkPlanExamine)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{

					public Object doInHibernate(Session arg0)
							throws HibernateException, SQLException {
						// TODO Auto-generated method stub
						Query query =	arg0.createQuery("from WorkPlanExamine work inner join fetch  work.workPlanMain where work.tjsUser.id = ? and work.workPlanMain.id = ?");
						query.setParameter(0, userid);
						query.setParameter(1, jihua);
						return query.uniqueResult();
					}
					
				});
	}
}
